package org.windblog.core.servlet.category;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.windblog.core.CategoryService;
import org.windblog.core.entity.Category;

@SuppressWarnings("serial")
public class DeleteCategoryServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String name = request.getParameter("cat");
		if(!CategoryService.isExist(name))
		{
			response.sendRedirect("/admin/categories.jsp?message=3");
		}else{
			Category cat = CategoryService.getCategory(name);
			CategoryService.deleteCategory(cat);
			response.sendRedirect("/admin/categories.jsp?message=4");
		}


	}
	
}